package org.mags.exception.common;

import org.apache.commons.validator.GenericValidator;

public class ExceptionDescriptor {
	private Throwable throwable;
	private String key;
	private String resolvedKey;
	private String message;
	private String stackTrace;
	private String extraDetail;
	
	public String getDescription() {
		String string = "class name: " + throwable.getClass().getName();
		string = string + "\r\n";
		string = string + "detail: ";
		string = string + "\r\n";
		string = string + (extraDetail==null?"":extraDetail);
		string = string + "\r\n";
		string = string + "key exception: error." +  key;
		string = string + "\r\n";
		string = string + "resolved by: " + (GenericValidator.isBlankOrNull(resolvedKey)?("error."+key):resolvedKey);
		string = string + "\r\n";
		string = string + "stack trace: ";
		string = string + "\r\n";
		string = string + stackTrace;
		return string;
	}
	
	public void addExtraData(String extraData) {
		if(message==null)
			message = extraData;
		else
			message = message + extraData;
	}
	
	public String getResolvedKey() {
		return resolvedKey;
	}

	public void setResolvedKey(String resolvedKey) {
		this.resolvedKey = resolvedKey;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public String getExtraDetail() {
		return extraDetail;
	}

	public void addExtraDetail(String extraDetail) {
		if(this.extraDetail==null)
			this.extraDetail = extraDetail;
		else
			this.extraDetail = this.extraDetail + extraDetail;
	}

	public String getStackTrace() {
		return stackTrace;
	}

	public void setStackTrace(String stackTrace) {
		this.stackTrace = stackTrace;
	}

	public Throwable getThrowable() {
		return throwable;
	}

	public String getKey() {
		return key;
	}

	public ExceptionDescriptor(Throwable throwable, String key) {
		if(throwable==null)
			throw new RuntimeException("throwsable can't be null");
		if(GenericValidator.isBlankOrNull(key))
			throw new RuntimeException("key can't be empty");
		this.throwable = throwable;
		this.key = key;
	}
}
